package cn.idu.socket.udp.chat;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetSocketAddress;

public class UDPSender {
    public static void main(String[] args) throws IOException {
        DatagramSocket socket = new DatagramSocket(8888);

        //准备数据
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        while (true) {
            String s = reader.readLine();
            byte[] data = s.getBytes();
            DatagramPacket packet = new DatagramPacket(data, data.length,
                    new InetSocketAddress("127.0.0.1", 6666));
            socket.send(packet);
            if (s.equals("bye")) break;
        }
        socket.close();
    }
}
